﻿using System;
using System.IO;
using Microsoft.Win32;

namespace ShortcutToolbox.Core
{
    public class Utils
    {
        private static string AppDataDirectoryPath = null;
        private static string UserProfileDirectoryPath = null;

        public static string GetAppDataDirectoryPath()
        {
            if (AppDataDirectoryPath == null)
            {
                AppDataDirectoryPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
                AppDataDirectoryPath = Path.Combine(AppDataDirectoryPath, "ShortcutToolbox");
            }
            return AppDataDirectoryPath;
        }

        public static string GetUserProfileDirectoryPath()
        {
            if (UserProfileDirectoryPath == null)
            {
                string userProfileDirectory = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
                UserProfileDirectoryPath = Path.Combine(userProfileDirectory, "ShortcutToolbox");
            }
            return UserProfileDirectoryPath;
        }

        public static string GetAppDataFilePath(params string[] paths)
        {
            return Path.Combine(GetAppDataDirectoryPath(), Path.Combine(paths));
        }

        public static string GetUserProfileDirectoryPath(params string[] paths)
        {
            return Path.Combine(GetUserProfileDirectoryPath(), Path.Combine(paths));
        }

        public static RegistryKey OpenUserRegKey(string name, bool writable)
        {
            RegistryKey userKey = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser,
                Environment.Is64BitOperatingSystem ? RegistryView.Registry64 : RegistryView.Registry32);
            userKey = userKey.OpenSubKey(name, writable);
            return userKey;
        }
    }
}
